<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" name="username" id="username" />
    <input type="text" name='age' id="age" />
    <button id="btn">添加</button>
</body>
<script>
    var username = document.getElementById('username');
    var age = document.getElementById('age');
    var btn = document.getElementById('btn');
    btn.onclick = function () {
        username = username.value;
        age = age.value;
        var formData = new FormData();
        formData.append('username', username);
        formData.append('age', age);

        fetch("http://localhost:8000", {
            method: 'POST',
            body: formData,
            headers: {
                'Content-Type': "text/plain"
            }
        }).then(res => res.text()).then((res) => {
            console.log(res);
        })
    }
</script>

</html>